"""
    菜品添加页面层
"""
from time import sleep

from selenium.webdriver.common.by import By

from base.base_page import BasePage


class PageDishAdd(BasePage):
    # 初始化属性
    def __init__(self):
        # 初始化父类属性
        super().__init__()
        # 菜品管理按钮
        self.dish_manager_btn = (By.XPATH, "//span[contains(text(),'菜品管理')]")
        # 初始化添加菜品的数据

        # 点击菜品添加按钮
        self.dish_add_btn =(By.XPATH, "//span[contains(text(),'新建菜品')]")
        #  请输入菜品名称
        self.dish_add_name = (By.CSS_SELECTOR, "input[placeholder*='请填写菜品名称']")

        # 输入菜品价格
        self.dish_price = (By.CSS_SELECTOR, "input[placeholder*='菜品价格']")

        # 选择菜品分类
        self.dish_sort = (By.CSS_SELECTOR, "input[placeholder*='菜品分类']")
        # # 等待选项出现并点击
        self.el =(By.XPATH, "//span[contains(text(),'广油')]")
        # 上传菜品图片
        self.upload_png =(By.CSS_SELECTOR, ".avatar-uploader-icon + input[type='file']")
        # 输入菜品描述
        self.dish_description = (By.CSS_SELECTOR, ".el-textarea__inner")
        # 点击保存
        self.dish_save_btn =(By.CSS_SELECTOR, "button.el-button--primary.continue")



    def page_dish_add(self):
        # 点击菜品管理，转到菜品管理页面
        self.base_click(self.dish_manager_btn)
        # 点击菜品添加按钮
        self.base_click(self.dish_add_btn)
        sleep(1)
        # 请输入菜品名称
        self.base_input_text(self.dish_add_name,"广油拉面")
        # 输入菜品价格
        self.base_input_text(self.dish_price,"10")
        # 点击菜品分类
        self.base_click(self.dish_sort)
        # 在菜品分类下选择“广油量大管饱菜”标签
        self.base_click(self.el)
        # 上传图片
        # self.base_input_text(self.upload_png,r"C:\Users\13428154264\OneDrive\图片\2.jpg")
        self.base_upload()
        # 输入描述
        self.base_input_text(self.dish_description,"广油拉面，吃了就不会亏，味道很棒，同学们多来品尝！")
        # 点击保存按钮
        self.base_click(self.dish_save_btn)
